cmake_minimum_required(VERSION 3.22)

# ------ 设置语言标准 ------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# ------ 引入 BSP 配置
include(BSP/BSP/gcc-arm-none-eabi.cmake)

# ------ 设置项目名 ------
set(CMAKE_PROJECT_NAME osDemo)

# ------ 配置项目 ------
project(${CMAKE_PROJECT_NAME} LANGUAGES C CXX ASM)
message("Build type: " ${CMAKE_BUILD_TYPE})

# ------ 添加公共宏 ------
add_definitions(
        -DTX_INCLUDE_USER_DEFINE_FILE
        -DTX_EXECUTION_PROFILE_ENABLE
        -DTX_CORTEX_M_EPK
)

# ------ 生成可执行文件 ------
add_executable(${CMAKE_PROJECT_NAME}
        App/App.cpp
)

# ------ 添加源文件 ------
file(GLOB_RECURSE source_c CONFIGURE_DEPENDS
        App/*.cpp App/*.c App/*.h
)
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
        ${source_c}
)
# ------ 添加头文件目录 ------
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
        App/include
)
# ------ 添加链接配置 ------
# ---- 添加 浮点数打印
target_link_options(${CMAKE_PROJECT_NAME} PUBLIC
        -u _printf_float
)

# ------ 通用配置 ------
# ---- 添加静态库
# -- sheriff_os
add_subdirectory(SheriffOS)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC os)
# -- bsp
#set(BSP_USER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/config/bsp_user.h)
add_subdirectory(BSP)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC bsp)
# ---- Device
add_subdirectory(Device)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC device)

# ---- 生成bin和hex
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
        COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.hex
        COMMAND ${CMAKE_OBJCOPY} -O binary -S $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.elf
) 